<%@ page contentType="text/html;charset=UTF-8"%>
<script type="text/javascript">
	//是否服务器分页
	var _isServerPage = true;
	//表格列定义
	var _tableCols = 	[/* {
		data : "uuid",
		orderable : false,
		className : "center",
		width : "30",
		render : RapDataTableUtils.renderCheckCol
	}, */
	{
		data : 'contract.contractNum',
		width : "80",
		render : function(data, type, full){
			return "<a href='#' onclick='onViewContract(this,\""+full.contract.uuid+"\");'>"+data+"</a>";
		},
		orderable : true
	},
	{
		data : 'contract.custom.theName',
		width : "120",
		//render : function(data, type, full){},
		orderable : true
	},
	{
		data : 'beginDate',
		width : "60",
		//render : function(data, type, full){},
		orderable : true
	},
	{
		data : 'endDate',
		width : "60",
		//render : function(data, type, full){},
		orderable : true
	},
	{
		data : 'shouldPayDate',
		width : "100",
		orderable : false
	},
	{
		data : 'shouldPayMoney',
		width : "100",
		className:"rap-td-number",
		render:milliFormat,
		orderable : false
	},
	{
		data : 'repayMoney',
		width : "100",
		className:"edit rap-td-number",
		render:milliFormat,
		orderable : false
	},
	{
		data : 'prepayMoney',
		width : "100",
		className:"edit rap-td-number",
		render:milliFormat,
		orderable : false
	},
	{
		data : 'payDate',
		width : "60",
		//render : function(data, type, full){},
		orderable : true
	},
	{
		data : 'money',
		width : "80",
		className:"rap-td-number",
		render:milliFormat,
		orderable : true
	},
	{
		data : 'leave',
		width : "80",
		className:"rap-td-number",
		render:milliFormat,
		orderable : true
	},
	/* {
		data : 'isInit',
		width : "80",
		render:function(data, type, full){
			return RapDataUtils.getEnumName("BooleanType", data);
		},
		orderable : true
	}, */
	/* {
		data : 'history',
		width : "50",
		className:"rap-td-number",
		render:milliFormat,
		orderable : true
	}, */
	{
		data : 'depositNow',
		width : "50",
		className:"rap-td-number",
		render:milliFormat,
		orderable : false
	},
	{
		data : 'remark',
		width : "200",
		className:"edit",
		orderable : false
	}
	/* {
		data : 'periodAndPrice',
		width : "50",
		className:"rap-td-number",
		render:milliFormat,
		orderable : false
	} *//* ,
	{
		data : "uuid",
		className : "center",
		orderable : false,
		render : RapDataTableUtils.renderActionCol,
		width : "80"
	} */]
;

	//宏：生成ShowData方法，在编辑框显示记录数据
	function showData(data) {
		$("input[name='uuid']").val(data.uuid);
		$("input[name='contract.contractNum']").val(data.contract.contractNum);
		$("input[name='contract.uuid']").val(data.contract.uuid);
		$("input[name='payDate']").val(data.payDate);
		$("select[name='beginMonth']").val(data.beginMonth);
		$("select[name='endMonth']").val(data.endMonth);
		$("input[name='money']").val(data.money);
		$("input[name='history']").val(data.history);
		$("input[name='depositNow']").val(data.depositNow);
		$("input[name='depositHistory']").val(data.depositHistory);
		$("input[name='periodAndPrice']").val(data.periodAndPrice);
		$("input[name='remark']").val(data.remark);
	}
	
	function callbackContract(data){
		$("#contractId").val(data.uuid);
		$("#contractNum").val(data.contractNum);
	}
	function bindOtherActions(){
		$("#rap-btn-ref-contractNum").colorbox({
			iframe : true,
			opacity	: 0.2,
			transition : 'none',
			speed : 200,
			href : "${ctx}/lease/contract/select?search_EQ_status=1&callback=callbackContract",
			innerWidth : '70%',
			innerHeight : '80%',
			close : '×',
			fixed : true
		});
		$('#contractNum').bind('focus', function(){
			$("#rap-btn-ref-contractNum").click();
		});
		
	}
	RapDataTableUtils.setActions=function(nRow, aData, iDataIndex){}
	function onViewContract(obj,uuid){
		$(obj).colorbox({
			iframe:true,
			opacity	: 0.2,
			overlayClose:true, 
			transition : 'none',
			speed : 200,
			href : "${ctx}/lease/contract/view?uuid="+uuid,
			innerWidth : '90%',
			innerHeight : '85%',
			close : '×',
			fixed : true
		});
	}
	$(document).ready(function() {
		bindDefaultActions();
		bindOtherActions();
		_queryData = $("#rap-form-query").serializeArray();
		if(_isServerPage){
			//服务器分页
			serverPage();	
		}else{
			//非服务器分页
			_tableList = $('#rap-table-list').DataTable({
				"columns" : _tableCols,
				"createdRow" : RapDataTableUtils.setActions,
				"order": [] 
			});
			loadList();		
		}
		
		RapDataTableUtils.setCheckCol(_tableList);

		/**
		 * 表单校验
		 */
		_validator = $('#rap-form-edit').validate({
					rules : {
						'contract.uuid' : {
							required : true
						}
					},
					messages : {
					}
				});
	});
</script>